package com.AAA.controller.sas;

import com.AAA.entity.LayData;
import com.AAA.entity.MyPage;
import com.AAA.entity.sas.TTestRecondSas;
import com.AAA.entity.User;
import com.AAA.service.sas.TTestRecondSasService;
import com.AAA.entity.sas.TTestRecondSas1;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * (TTestRecondSas)表控制层
 *
 * @author 何泽明
 * @since 2022-11-05 08:58:21
 */
@RestController
@RequestMapping("tTestRecondSas")
public class TTestRecondSasController {
    /**
     * 服务对象
     */
    @Autowired
    private TTestRecondSasService service;

    @PostMapping("add")
    private LayData add(HttpServletRequest request, HttpSession session){
        String username = request.getParameter("username");
        Integer id = service.selectidbyusername(username);
        Integer rid = service.selectusernameidbyusername(id);
        if (rid>0){
            return new LayData(false);
        }
        return new LayData(service.add(request,session));
    }
    //分页查询
    @GetMapping("selectall")
    public  LayData selectall(MyPage myPage, TTestRecondSas1 tTestRecondSas){
        return  new LayData(service.selectall(myPage,tTestRecondSas));
    }
    //修改
    @PostMapping ("update")
    public LayData update(TTestRecondSas tTestRecondSas,HttpSession session){
        User user = (User) session.getAttribute("user");
        tTestRecondSas.setUpdateby(user.getUsername());
        return new LayData(service.update(tTestRecondSas));
    }
    //删除
    @PostMapping("del")
    @ResponseBody
    public LayData delete(Integer id){
        return new LayData( service.delete(id));
    }

}

